<template>
  <DialogSubmitForm v-bind="formFrame" ref="form" />
</template>
<script setup lang="ts">
import { MDialogSubmitForm as DialogSubmitForm } from "page-com";
import { shallowReactive, useTemplateRef } from "vue";
import { updateDict } from "@/api/system/dictApi";
import { DialogSubmitFormFrame } from "page-com";
import { successMsg } from "@/utils/message";
const form = useTemplateRef("form");
const formFrame = shallowReactive<DialogSubmitFormFrame>({
  submitFun: async function (data) {
    let res = await updateDict(data);
    if (res.code == RESPONSE_CODE.SUCCESS) {
      successMsg("修改成功");
      emit("saveSuccess", data);
      form.value.hide();
    }
  },
  width: "400px",
  items: [
    {
      frameType: "input",
      key: "name",
      label: "名称",
      validations: {
        required: true
      }
    },
    {
      frameType: "input-tag",
      key: "value",
      label: "值",
      validations: {
        required: true
      }
    },
    {
      frameType: "input",
      key: "type",
      label: "类型",
      validations: {
        required: true
      }
    }
  ]
});
function show(vo: ShopDictVo) {
  form.value.show(vo);
}

defineExpose({ show });
const emit = defineEmits<{
  saveSuccess: [data: ShopDictVo];
}>();
</script>
